home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / MotifApp / Extras / TicTacToe / Message.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  1.9 KB  |  70 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //////////////////////////////////////////////////////////////////////////////
  3. //         This example code is from the book:
  4. //
  5. //           Object-Oriented Programming with C++ and OSF/Motif
  6. //         by
  7. //           Douglas Young
  8. //           Prentice Hall, 1992
  9. //           ISBN 0-13-630252-1    
  10. //
  11. //         Copyright 1991 by Prentice Hall
  12. //         All Rights Reserved
  13. //
  14. //  Permission to use, copy, modify, and distribute this software for 
  15. //  any purpose except publication and without fee is hereby granted, provided 
  16. //  that the above copyright notice appear in all copies of the software.
  17. ///////////////////////////////////////////////////////////////////////////////
  18. //////////////////////////////////////////////////////////////////////////////
  19.  
  20.  
  21. /////////////////////////////////////////////////////////
  22. // Message.C: Manages a message panel, 
  23. //            using an XmLabel widget
  24. /////////////////////////////////////////////////////////
  25. #include "Message.h"
  26. #include <Xm/Xm.h>
  27. #include <Xm/Label.h>
  28. #include <assert.h>
  29.  
  30. Message::Message ( Widget parent, char * name ) : UIComponent( name )
  31. {
  32.     _w = XmCreateLabel ( parent, _name, NULL, 0 );
  33.     installDestroyHandler();
  34.     postMessage ( " " );  // Clear the widget
  35. }
  36.  
  37.  
  38. void Message::postMessage ( char *msg )
  39. {
  40.     assert ( _w );
  41.     
  42.     // Convert the character string to a compound string for Motif
  43.     
  44.     XmString xmstr = XmStringCreateSimple ( msg );
  45.     
  46.     // Display the new label
  47.     
  48.     XtVaSetValues ( _w, XmNlabelString, xmstr, NULL ); 
  49.     
  50.     // XmLabel copies the string, so we can free our copy
  51.     
  52.     XmStringFree ( xmstr );
  53. }
  54.  
  55. void Message::postAlert ( char *msg )
  56. {
  57.     assert ( _w );  // Must have a widget to display message
  58.     
  59.     if ( msg )
  60.     postMessage ( msg );  // Display the string
  61.     
  62.     // Sound a bell as an alert. 
  63.     
  64.     XBell ( XtDisplay ( _w ), 100 );
  65. }
  66.  
  67.  
  68.  
  69.  
  70.